#pragma once

/*
作用：
特意定义一个这个宏主要是为了防止写错

比如比较回调写成这样:
[](char left, char right) {
    return left - right;
}

有些回调接口形如 icallback<ixx(char const &, char const &)>，对签名要求严格，
上述回调就不符合签名要求

正确的写法如下：
[](char const & left, char const & right) -> ixx {
    return ixx(left - right);
}

*/

#define __xcmpx(LEFT,RIGHT,...)             (__VA_ARGS__ const & LEFT, __VA_ARGS__ const & RIGHT) -> ixx
#define __xcmp_fieldx(LEFT,RIGHT,FIELD,...)             \
    __xcmpx(LEFT,RIGHT, ## __VA_ARGS__){                \
        return                                          \
            left FIELD < right FIELD ? -1 :             \
            left FIELD > right FIELD ? +1 : 0;          \
    }

#define xcmp(...)                                   [&]__xcmpx(left, right, ## __VA_ARGS__)
#define xcmpx(LEFT,RIGHT,...)                       [&]__xcmpx(LEFT, RIGHT, ## __VA_ARGS__)
#define xcmp_global(...)                            [ ]__xcmpx(left, right, ## __VA_ARGS__)
#define xcmp_globalx(LEFT,RIGHT,...)                [ ]__xcmpx(LEFT, RIGHT, ## __VA_ARGS__)
#define xcmp_field(FIELD,...)                       [&]__xcmp_fieldx(left, right, FIELD, ## __VA_ARGS__)
#define xcmp_fieldx(LEFT,RIGHT,FIELD,...)           [&]__xcmp_fieldx(LEFT, RIGHT, FIELD, ## __VA_ARGS__)
#define xcmp_field_global(FIELD,...)                [ ]__xcmp_fieldx(left, right, FIELD, ## __VA_ARGS__)
#define xcmp_field_globalx(LEFT,RIGHT,FIELD,...)    [ ]__xcmp_fieldx(LEFT, RIGHT, FIELD, ## __VA_ARGS__)
